const express = require('express');
const router = express.Router();
const opera = require('../utils/dbOperation')
const result = require('../utils/response')
const time = require('../utils/timeUtils')
const uid = require('../utils/getUid')

router.post('/list',(req,res) =>{
  const data = req.body;
  data.del_flag = 0;
  opera.select("pro_module",data,(results) => {
    res.send(result.success(results));
  },null,'create_time')
})

router.delete('/delete',(req,res) =>{
  const data = req.body;
  opera.update('pro_module',{del_flag:1,update_time:time.getNowFormatDate()},data,(back) => {
    res.send(result.success());
  })
})

router.put('/update',(req,res) =>{
  const data = req.body;
  const id = data.id;
  delete data.id;
  data.update_time = time.getNowFormatDate()
  opera.update('pro_module',data,{id:id},(back) => {
    res.send(result.success());
  })
})

router.post('/add',(req,res) =>{
  const data = req.body;
  data.id = uid();
  data.update_time = time.getNowFormatDate()
  data.create_time = time.getNowFormatDate()
  opera.insert('pro_module',data,(back) => {
    res.send(result.success());
  })
})

module.exports = router;
